package org.wedding.center.service.impl;

import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import org.wedding.center.service.WxPayService;
import org.wedding.center.mapper.WxPayMapper;
import org.wedding.center.entity.WxPay;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.wedding.enums.system.ResultCodeEnum;
import org.wedding.utils.CommonResult;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.IdUtil;
import cn.dev33.satoken.stp.StpUtil;
import cn.hutool.core.util.ObjectUtil;
import org.springframework.stereotype.Service;
import cn.hutool.core.util.ObjectUtil;
import org.wedding.dto.PageModel;
import org.wedding.utils.PageUtil;
import org.springframework.transaction.annotation.Transactional;
import org.wedding.center.dto.query.WxPayQuery;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;

/**
 * 微信支付信息表(wedding) 表服务实现类
 *
 * @author 2025-07-17 15:10:25
 * @since sky
 */
@Service
public class WxPayServiceImpl extends ServiceImpl<WxPayMapper, WxPay> implements WxPayService {

    /**
     * 分页查询所有数据
     *
     * @return
     */
    @Override
    public CommonResult<WxPayQuery> findAll(WxPayQuery query) {
        try {
            List<WxPay> list = baseMapper.selectAll(query);
            List<WxPay> setList = query.setList(PageUtil.getListPage(query.getCurrent(), query.getPageSize(), list), list.size());
            query.setList(setList, list.size());
            return CommonResult.success(query);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed(ResultCodeEnum.API_ERROR);
        }
    }


    /**
     * 根据id查看详情
     *
     * @param id
     * @return
     */
    @Override
    public CommonResult<WxPay> view(String id) {
        try {
            WxPay wxPay = baseMapper.findById(id);
            return CommonResult.success(wxPay);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed(ResultCodeEnum.API_ERROR);
        }
    }

    /**
     * 新增数据
     *
     * @param wxPay
     * @return
     */
    @Override
    public CommonResult add(WxPay wxPay) {
        try {
//            String userId = StpUtil.getSession().get("userId").toString();
//            String userName = StpUtil.getSession().get("userName").toString();
//            wxPay.setCreator(userId);
//            wxPay.setCreatorName(userName);
            wxPay.setId(IdUtil.simpleUUID());
            wxPay.setCreateTime(DateUtil.now());
            wxPay.setDelFlag("0");
            baseMapper.insert(wxPay);
            return CommonResult.success(wxPay);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed(ResultCodeEnum.API_ERROR);
        }
    }

    /**
     * 修改数据
     *
     * @param wxPay
     * @return
     */
    @Override
    public CommonResult updateEntity(WxPay wxPay) {
        try {
            wxPay.setUpdateTime(DateUtil.now());
            baseMapper.updateById(wxPay);
            return CommonResult.success(wxPay);
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed(ResultCodeEnum.API_ERROR);
        }
    }

    /**
   * 删除数据
   *
   * @param ids
   * @return
   */
    @Override
    public CommonResult delete(List<String> ids) {
        try {
            if (ObjectUtil.isEmpty(ids)) {
                return CommonResult.failed(ResultCodeEnum.PARAM_ERROR);
            }
            for (String id : ids) {
                baseMapper.upDeleteById(id);
            }
            return CommonResult.success();
        } catch (Exception e) {
            e.printStackTrace();
            return CommonResult.failed(ResultCodeEnum.API_ERROR);
        }
    }

}